package com.xbongbong.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.ext.ConditionsEntityExt;
import com.xbongbong.paas.elasticsearch.util.EsUtil;
import com.xbongbong.paas.enums.ConditionEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2022/05/13 15:28
 */
public class AddressUtil {


    /**
     * com.xbongbong.saas.help.SaasListHelp#addressSearchShouldCondition(com.xbongbong.paas.pojo.dto.FormDataListDTO)
     * @param shouldConditionList
     */

    public static void addressSearchShouldCondition(List<List<ConditionsEntityExt>> shouldConditionList) {
        shouldConditionList = Objects.isNull(shouldConditionList) ? new ArrayList<>() : shouldConditionList;
        for (List<ConditionsEntityExt> conditionsEntityExts : shouldConditionList){
            Iterator<ConditionsEntityExt> iterator = conditionsEntityExts.iterator();
            while (iterator.hasNext()) {
                ConditionsEntityExt entityExt = iterator.next();
                if(Objects.equals(PaasConstant.PROVINCE, entityExt.getAttr()) || Objects.equals(PaasConstant.CITY, entityExt.getAttr())
                        || Objects.equals(PaasConstant.DISTRICT, entityExt.getAttr())) {
                    // 公海池分组：省、市、区
                    entityExt.setAttr(CustomerManagementEnum.ADDRESS.getAttr() + StringConstant.POINT + entityExt.getAttr());
//                    publicGroupAddressMap.put(entityExt.getAttr(), entityExt);
//                    iterator.remove();
                }
            }
        }
    }

    /**
     * com.xbongbong.saas.help.SaasListHelp#addressSearchCondition(com.xbongbong.paas.pojo.dto.FormDataListDTO)
     * 地址筛选条件
     *
     * @param conditions 参数
     * @return
     * @throws
     * @author hongxiao
     * @date 2019-07-05 09:17
     * @since v1.0
     * @version v1.0
     */
    public static void addressSearchCondition(List<ConditionsEntityExt> conditions, List<List<ConditionsEntityExt>> shouldConditionList) {
        EsUtil.addressSearchCondition(conditions, shouldConditionList);
    }
}
